<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>编辑商品SKU表(商品库存量单位表)</title>
	<#include "/common/vue_resource.ftl">
</head>
<body>
<div id="app" v-cloak>
	<div class="ui-form1" style="padding:10px;">
		<form class="layui-form" @submit.prevent="submitForm()" method="post">
			<table class="layui-table" style="margin:0;">
				<thead>
				<tr>
					<th>{{skuStandardTitle}}</th>
					<th>销售价格<span class="ui-request">*</span></th>
					<th>商品库存</th>
					<th>库存预警值</th>
					<th>SKU编号</th>
				</tr>
				</thead>
				<tbody>
				<tr v-for="(item, index) in skuStockList" :key="'skuStockList_' + index">
					<td>{{item.sp2}}</td>
					<td><input type="text" v-model="item.price" class="layui-input"></td>
					<td><input type="text" v-model="item.stock" class="layui-input"></td>
					<td><input type="text" v-model="item.lowStock" class="layui-input"></td>
					<td><input type="text" v-model="item.skuCode" class="layui-input"></td>
				</tr>
				</tbody>
			</table>

			<div class="layui-form-item" style="margin-top:10px;">
				<div class="layui-input-block">
					<input type="submit" value="保存" class="layui-btn" />
				</div>
			</div>
		</form>
	</div>
</div>
<script>
	var app = new Vue({
		el: '#app',
		data: {
			showTypes: false,
			record : {
				productId:'${params.productId!}',
				productAttributeCategoryId: '${params.attributeCategoryId!}',
				skuStockListStr: '',
			},
			skuStockList: [],
			skuStandardTitle: '',
		},
		mounted: function () {
			this.init();
			this.loadData();
		},
		methods: {
			init:function(){
				var that = this;
				/*laydate.render({elem: '#beginDate', type:'datetime', done:function (value) {
						that.record.beginDate = value;
					}});*/
			},
			loadAttribute: function () {//获取商品规格、商品参数
				var that = this;
				$.http.post('${params.contextPath}/web/pmsProductAttribute/queryList.json', {categoryId: this.record.productAttributeCategoryId}).then(function (data) {
					if (!data.success) {
						$.message(data.message);
						return;
					}
					var list = data.data, stanardTitle = [];
					that.attributeStandardList = [];
					for (var i = 0, size = list.length; i < size; i++) {
						var record = list[i];
						if (record.type == 0) {
							stanardTitle.push(record.name);
						}
					}
					that.skuStandardTitle = stanardTitle.join(" / ") || "--";
				});
			},
			loadData: function () {
				var that = this;
				$.http.post('${params.contextPath}/web/pmsSkuStock/list.json', {productId: '${params.productId!}'}).then(function (data) {
					if (!data.success) {
						$.message(data.message);
						return;
					}
					that.skuStockList = data.data;
					that.loadAttribute();
				});
			},
			submitForm: function () {
				this.record.skuStockListStr = JSON.stringify(this.skuStockList);
				$.http.post('${params.contextPath}/web/pmsSkuStock/modify.json', this.record).then(function (data) {
					if (!data.success) {
						$.message(data.message);
						return;
					}
					var alt = layer.alert(data.message || "操作成功", function () {
						//parent.app.loadData();
						parent.layer.closeAll();
						layer.close(alt);
					});
				});
			},
		}
	});
</script>
</body>

</html>
